<template>
  <div class="box">
    <div class="top">
      <div class="cont">
        <div class="cont">
          <p class="route-text">
            <img src="../assets/home.png" class="home" alt="" @click="toHome">
            <span class="span-margin">/</span>
            <span>公告</span>
          </p>
          <p class="title">公告</p>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="board-item" v-for="item in list" :key="item.id" @click="boardClick(item)">
        <p class="title-text">{{item.newsTitle}}</p>
        <p class="board-text">{{item.createTime}}</p>
      </div>
      <button class="check-more" @click="checkedMore">查看更多<img src="../assets/arrow.png" class="arrow-right" alt=""></button>
    </div>
  </div>
  
</template>

<script>
  import Swiper from "../components/swiper.vue"
  import newsList from "../components/newlist.vue"
  import {
    getNewsByCategoryId,
    selectNewsCategorys,
  } from "@/api/home"
  export default {
    components: {
      Swiper,
      newsList
    },
    data() {
      return {
        list: [],
        boradId: 0,
        pageNum: 1,
        pageSize: 6,
        total: 0
      }
    },
    methods: {
      toHome(){
        this.$router.push("/")
      },
      selectNewsCategorys() {
        selectNewsCategorys({}).then(res => {
          this.titlelist = res.result;
          res.result.forEach(item => {
            if (item.newsCategoryName === "公告") {
              this.boradId = item.id;
            }
          })
        })
      },
      getNewsByCategoryId() {
        getNewsByCategoryId({
          newCategoryId: this.boradId,
          pageNum: this.pageNum,
          pageSize: this.pageSize
        }).then(res => {
          if (res.code == 200) {
            if (res.result == null) {
              return;
            }
            this.list = this.list.concat(res.result.list);
            this.total = res.result.total;
          } else {
            this.$message('暂无更多');
          }
        })
      },
      boardClick(item) {
        this.$router.push({
          path: '/boarddetail',
          name: 'boarddetail',
          query: {
            id: item.id
          }
        })
      },
      checkedMore(){
        var totalPage = (this.total % this.pageSize == 0 ? this.total / this.pageSize : this.total / this.pageSize + 1);
        if (this.pageNum < totalPage) {
          this.pageNum++;
          this.getNewsByCategoryId()
        }else{
          this.$message('暂无更多');
        }
      }
    },
    mounted() {},
    created() {
      this.selectNewsCategorys();
      setTimeout(() => {
        this.getNewsByCategoryId();
      }, 500)
    }
  }
</script>

<style scoped="scoped">
  .box {
    width: 100%;
  }

  .top {
    width: 100%;
    height: 120px;
    background-color: #106470;
    padding-top: 0px;
    box-sizing: border-box;
  }

  .cont {
    width: 1200px;
    margin: 0 auto;
  }

  .content {
    width: 1200px;
    margin: 0 auto;
    margin-top: 30px;
    padding: 0 15px;
    box-sizing: border-box;
  }

  .route-text {
    font-size: 12px;
    font-family: Microsoft YaHei;
    font-weight: 300;
    line-height: 26px;
    color: #FFFFFF;
    height: 55px;
    display: flex;
    align-items: center;
  }

  .span-margin {
    margin: 0 6px;
  }

  .home {
    width: 16px;
    height: 16px;
    cursor: pointer;
  }

  .title {
    font-size: 24px;
    font-family: Microsoft YaHei;
    font-weight: 300;
    line-height: 26px;
    color: #FFFFFF;
    margin-top: 10px;
  }

  .name-text {
    font-size: 24px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 31px;
    color: #000000;
    margin-bottom: 20px;
  }

  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 28px;
    color: #333333;
  }

  .policy-title {
    margin: 0 auto;
    width: 830px;
    font-size: 24px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 38px;
    color: #000000;
    text-align: center;
  }

  .policy-time {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 19px;
    color: #999999;
    text-align: center;
    margin-top: 15px;
  }

  .policy-time span:first-child {
    margin-right: 20px;
  }

  .board-item {
    display: flex;
    justify-content: space-between;
    margin-top: 18px;
    border-bottom: 1px solid #E5E5E5;
    padding-bottom: 18px;
    cursor: pointer;
  }

  .board-text {
    font-size: 12px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 24px;
    color: #6F6F6F;
  }

  .title-text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 24px;
    color: #0070C0;
  }

  .check-more {
    width: 118px;
    height: 32px;
    background: #000000;
    border: none;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 32px;
    color: #FFFFFF;
    margin-top: 30px;
  }

  .arrow-right {
    width: 6px;
    height: 11px;
    margin-left: 12px;
  }
</style>
